﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfControlDemo.Models;

namespace WpfControlDemo.数据模版.项模版
{
    /// <summary>
    /// ItemTemplateWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ItemTemplateWindow : Window
    {
        public ItemTemplateWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<ClassInfo> classList = GetClassList();
            lbList.ItemsSource = classList; // 数据源绑定
            //设置项目模板后就不能在指定这个属性了
            // lbList.DisplayMemberPath = "ClassName";
            lbList.SelectedValuePath = "ClassId"; 
            cboList.ItemsSource = classList;  // 数据源绑定
        }

        /// <summary>
        /// 获取班级信息列表
        /// </summary>
        /// <returns></returns>
        public List<ClassInfo> GetClassList()
        {
            List<ClassInfo> list = new List<ClassInfo>();
            for (int i = 1; i <= 20; i++)
            {
                ClassInfo classInfo = new ClassInfo();
                classInfo.ClassId = i;
                classInfo.ClassName = $"项目名称-{i}";
                list.Add(classInfo);
            }
            return list;
        }
    }
}
